{{extend '../_layouts/home.html'}}

{{block 'title'}}{{'多人博客 - 首页'}}{{/block}}

{{block 'body'}}
<section class="container">
  {{include '../_partials/settings-nav.html'}}
  <div class="col-md-5">
    <form id="update-self-info">
      <div class="form-group">
        <label for="exampleInputEmail1">账号</label>
        <p class="form-control-static">{{ user.email }}</p>
      </div>
      <div class="form-group">
        <label for="exampleInputPassword2">昵称</label>
        <input type="text" class="form-control" name="nickname" id="exampleInputPassword2" value="{{ user.nickname }}">
      </div>
      <div class="form-group">
        <label for="exampleInputPassword1">介绍</label>
        <textarea class="form-control" rows="3" name="bio">{{ user.bio }}</textarea>
      </div>
      <div class="form-group">
        <label for="exampleInputPassword1">性别</label>
        <div>
          {{ if user.gender == -1 }}
          <label class="radio-inline">
            <input type="radio" name="inlineRadioOptions" name="gender" id="inlineRadio1" value="option1"> 男
          </label>
          <label class="radio-inline">
            <input type="radio" name="inlineRadioOptions" name="gender" id="inlineRadio2" value="option2"> 女
          </label>
          <label class="radio-inline">
            <input type="radio" name="inlineRadioOptions" name="gender" id="inlineRadio3" value="option3" checked> 保密
          </label>
          {{ else if user.gender == 0 }}
          <label class="radio-inline">
            <input type="radio" name="inlineRadioOptions" name="gender" id="inlineRadio1" value="option1" checked> 男
          </label>
          <label class="radio-inline">
            <input type="radio" name="inlineRadioOptions" name="gender" id="inlineRadio2" value="option2"> 女
          </label>
          <label class="radio-inline">
            <input type="radio" name="inlineRadioOptions" name="gender" id="inlineRadio3" value="option3"> 保密
          </label>
          {{ else if user.gender == 1 }}
          <label class="radio-inline">
            <input type="radio" name="inlineRadioOptions" name="gender" id="inlineRadio1" value="option1"> 男
          </label>
          <label class="radio-inline">
            <input type="radio" name="inlineRadioOptions" name="gender" id="inlineRadio2" value="option2" checked> 女
          </label>
          <label class="radio-inline">
            <input type="radio" name="inlineRadioOptions" name="gender" id="inlineRadio3" value="option3"> 保密
          </label>
          {{ /if }}
        </div>
      </div>
      <div class="form-group">
        <label for="exampleInputPassword1">生日</label>
        {{ if user.birthday }}
        <input type="text" class="form-control" name="birthday" id="exampleInputPassword1"  value="{{ user.birthday }}">
        {{ else }}
        <input type="text" class="form-control" name="birthday" id="exampleInputPassword1" placeholder="请输入您的生日">
        {{ /if }}
      </div>
      <button type="submit" class="btn btn-success">保存</button>
    </form>
  </div>
  <div class="col-md-2 profile-avatar">
    <dl>
      <dt>头像设置</dt>
      <dd>
        <img class="avatar" width="150" height="150" src="../public/img/avatar-max-img.png" alt="">
        <div>
          <button class="btn btn-default" href="">Upload new picture</button>
        </div>
      </dd>
    </dl>
  </div>
</section>
{{/block}}
{{block 'script'}}
<script>
  $('#update-self-info').on('submit', function (e) {
      e.preventDefault()
      const formData = $(this).serialize()
      $.ajax({
        url: '/update',
        type: 'post',
        data: formData,
        dataType: 'json',
        success: function (data) {
          var err_code = data.err_code
          if (err_code === 0) {
            alert('修改成功');
            location.href = '/';

          } else if (err_code === 1) {
            window.alert('邮箱或者密码错误')
          } else if (err_code === 500) {
            window.alert('服务器忙，请稍后重试！')
          }
        }
      })
    })
</script>
{{/block}}
